Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types/custom-element): defineCustomElement with required props #11578

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

andylizi
Copy link
Contributor

Fixes type error when using defineCustomElement with required: true props.

const Comp1Vue = defineComponent({
  props: {
    a: { type: Number, required: true },
  },
})
const Comp = defineCustomElement(Comp1Vue)
//                               ^^^^^^^^ No overload matches this call. ts(2769)
No overload matches this call.
  The last overload gave the following error.
    Argument of type 'DefineComponent<ExtractPropTypes<{ a: { type: NumberConstructor; required: true; }; }>, ...>' is not assignable to parameter of type 'DefineComponent<any, any, any, any>'.
      Type 'DefineComponent<ExtractPropTypes<{ a: { type: NumberConstructor; required: true; }; }>, ...>' is not assignable to type 'ComponentOptionsBase<Readonly<any>, ...>'.
        Types of property 'setup' are incompatible.
          Type '(this: void, props: LooseRequired<Readonly<{ a: number; } & {} & {}> & {}>, ...) => void | ...' is not assignable to type '(this: void, props: LooseRequired<Readonly<any> & {}>, ...) => any'.
            Types of parameters 'props' and 'props' are incompatible.
              Property 'a' is missing in type 'LooseRequired<Readonly<any> & {}>' but required in type 'LooseRequired<Readonly<{ a: number; } & {} & {}> & {}>'.

In addition, this PR also removes an unnecessary ExtractPropTypes. Before this change:

const Comp: VueElementConstructor<ExtractPropTypes<ExtractPropTypes<{
    a: {
        type: NumberConstructor;
        required: true;
    };
}>>>
// `Comp` is `VueElementConstructor<{ a?: number | undefined }>`

After this change:

const Comp: VueElementConstructor<ExtractPropTypes<{
    a: {
        type: NumberConstructor;
        required: true;
    };
}>>
// `Comp` is `VueElementConstructor<{ a: number }>`

@yyx990803 yyx990803 merged commit 77d5e88 into vuejs:minor Aug 15, 2024
11 checks passed
@andylizi andylizi deleted the fix-ce-required-props branch August 15, 2024 03:21
edison1105 added a commit to edison1105/vuejs-core that referenced this pull request Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants